﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Common.Tests.System.Threading.Tasks
{
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
    [TestFixture]
    public class AsyncPumpTests
    {
        [Test]

        public async void Can_await_async_task()
        {
            AsyncPump.Run(async delegate
            {
                await DemoAsync();
            });
        }

        static async Task DemoAsync()
        {
            var d = new Dictionary<int, int>();

            for (int i = 0; i < 10000; i++)
            {

                int id = Thread.CurrentThread.ManagedThreadId;

                int count;
                d[id] = d.TryGetValue(id, out count) ? count + 1 : 1;

                await Task.Yield();
            }

            foreach (var pair in d)
                Console.WriteLine(pair);
        }

    }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
}
